package _021_10_8

func TreeDepth(pRoot *TreeNode) int {
	// write code here

	treeQueue := make([]*TreeNode, 0)
	treeQueue = append(treeQueue, pRoot)
	count := 0
	if pRoot == nil {
		return count
	}
	for len(treeQueue) != 0 {
		size := len(treeQueue)
		for i := 0; i < size; i++ {
			if treeQueue[i].Left != nil {
				treeQueue = append(treeQueue, treeQueue[i].Left)
			}
			if treeQueue[i].Right != nil {
				treeQueue = append(treeQueue, treeQueue[i].Right)
			}
		}
		count++
		copy(treeQueue, treeQueue[size:])
		treeQueue = treeQueue[0 : len(treeQueue)-size]
	}
	return count
}
